package com.imooc.project.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.imooc.project.dao.AccountMapper;
import com.imooc.project.dto.LoginDTO;
import com.imooc.project.entity.Account;
import com.imooc.project.service.AccountService;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhou
 * @since 2021-06-18
 */
@Service
public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> implements AccountService {

    @Override
    public LoginDTO login(String username, String password) {
        LoginDTO loginDTO = new LoginDTO();
        loginDTO.setPath("redirect:/");
        Account account = lambdaQuery().eq(Account::getUsername, username).one();
        if(account == null){
            loginDTO.setError("用户名不存在");
            return loginDTO;
        }
        if(!password.equals(account.getPassword())){
            loginDTO.setError("密码错误");
            return loginDTO;
        }
        loginDTO.setAccount(account);
        if(1==account.getAccountState()){
            loginDTO.setPath("login/main");
        }
        if(0==account.getAccountState()){
            loginDTO.setPath("login/main1");
        }
        return loginDTO;
    }
}
